<?php
/**
 * Model (table)
 * All models that relate to a database table should extend this class.
 *
 * @package     Visi
 * @subpackage  Models
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id$
 * @see         /application/configs/schema.sql for db schema
 * @todo        Make it so that rules have to pass for a model to save.
 * @todo        Make foreignKey rules automatically get added when a model
 *              has relationships defined
 */
class Visi_Db_Table extends Zend_Db_Table {

    protected $_rules;
    
    protected $_filters;
    
    public function init() {
    
        $this->_filters = new Q_Filter_Set();
        $this->_rules = new Visi_Rule_ModelSet($this);
    
    }
    
    public function getRules() {
    
        return $this->_rules;
    
    }
    
    public function getFilters() {
    
        return $this->_filters;
    
    }

    public function getModel($model) {
    
        $catalog = Zend_Controller_Action_HelperBroker::getExistingHelper('ModelCatalog');
        return $catalog->direct($model);
    
    }
    
    public function getCache($cacheName = 'database') {
    
        $cache = Zend_Controller_Front::getInstance()
            ->getParam('bootstrap')
            ->getResource('cachemanager')
            ->getCache($cacheName);
        return $cache;
    
    }
    
    /**
     * This is how models are to access the application configuration. I would
     * really prefer that models don't need to access application configuration
     * because they are supposed to be capable of being used anywhere, but oh
     * well.
     */
    public function getConfig() {
    
        return Zend_Controller_Front::getInstance()
            ->getParam('bootstrap')
            ->getOptions();
    
    }

}